import axios from "axios";

const apiService = axios.create({
    baseURL: "http://127.0.0.1:8000"
});
const NETWORK_ERROR = "网络错误...";

// 请求前
// apiService.interceptors.request.use((config) => {
//     return config;
// }, (error) => {
//     return Promise.reject(error);
// });

// 请求后
apiService.interceptors.response.use((res) => {
    if (res.data.code !== 0){
        ElMessage({
            message: res.data.msg || NETWORK_ERROR,
            type: "error"
        });
    }
    return res.data;
}, (error) => {
    return Promise.reject(error);
});


// 不填method默认是get
function request(options) {
    options.method = options.method || "get";
    return apiService(options);
}
export default request;